<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Model_record extends CI_Model {
	public function __construct(){
		parent::__construct();
	}

	public function add_record(){
		$data = array(
			'mssv' => $this->session->userdata('mssv'),
			'ten_hs' => $this->input->post('ten_hs'),
			'dia_chi' => $this->input->post('dia_chi'),
			'luong' => $this->session->userdata('luong'),
			'hinhthuc_tt' => $this->input->post('hinhthuc_tt'),
			'bang_cap' => $this->input->post('bang_cap'),
			'kinh_nghiem' => $this->input->post('kinh_nghiem'),
			'ki_nang' => $this->input->post('ki_nang'),
			'muc_tieu' => $this->input->post('muc_tieu'),
			'thanh_tich' => $this->input->post('thanh_tich'),
			'thoigian_tn' => $this->input->post('time_tn'),
			'cv' => $this->session->flashdata('message'),
			'active' =>0
			);
		$query = $this->db->insert('ho_so', $data);
		if($query) {
			return true;
		}else {
			return false;
		}
	}

	public function save_load(){
		$data = array(
			'mssv' => $this->session->userdata('mssv'),
			'ten_hs' => $this->input->post('ten_hs'),
			'dia_chi' => $this->input->post('dia_chi'),
			'luong' => $this->session->userdata('luong'),
			'hinhthuc_tt' => $this->input->post('hinhthuc_tt'),
			'bang_cap' => $this->input->post('bang_cap'),
			'kinh_nghiem' => $this->input->post('kinh_nghiem'),
			'ki_nang' => $this->input->post('ki_nang'),
			'muc_tieu' => $this->input->post('muc_tieu'),
			'thanh_tich' => $this->input->post('thanh_tich'),
			'thoigian_tn' => $this->input->post('time_tn'),
			'cv' => $this->session->flashdata('message'),
			'active' =>1
			);
		$query = $this->db->insert('ho_so', $data);
		if($query) {
			return true;
		}else {
			return false;
		}
	}

	public function list_record($mssv){
		$this->db->where('mssv', $mssv);
		$query = $this->db->get('ho_so');
		return $query->result_array();
	}

	public function active_record($id_hs){
		$data = array('active' => 1);
		$this->db->where('id', $id_hs);
		$query = $this->db->update('ho_so', $data);
		if($query){
			return true;
		}else{
			return false;
		}
	}

	public function deactive_record($id_hs){
		$data = array('active' => 0);
		$this->db->where('id', $id_hs);
		$query = $this->db->update('ho_so', $data);
		if($query){
			return true;
		}else{
			return false;
		}
	}

	public function deactive_another_record($id_hs, $mssv){
		$data = array('active' => 0);
		$this->db->where('id !=', $id_hs);
		$this->db->where('mssv', $mssv);
		$query = $this->db->update('ho_so', $data);
		if($query){
			return true;
		}else{
			return false;
		}
	}

	public function record_detail($id_hs){
		$this->db->where('id', $id_hs);
		$query = $this->db->get('ho_so');
		return $query->row_array();
	}

	public function delete_record($id_hs){
		$this->db->where('id', $id_hs);
		$query = $this->db->delete('ho_so');
		if($query){
			return true;
		}else{
			return false;
		}
	}

	public function edit_record($id_hs){
		$data = array(
			'mssv' => $this->session->userdata('mssv'),
			'ten_hs' => $this->input->post('ten_hs'),
			'dia_chi' => $this->input->post('dia_chi'),
			'luong' => $this->session->userdata('luong'),
			'hinhthuc_tt' => $this->input->post('hinhthuc_tt'),
			'bang_cap' => $this->input->post('bang_cap'),
			'kinh_nghiem' => $this->input->post('kinh_nghiem'),
			'ki_nang' => $this->input->post('ki_nang'),
			'muc_tieu' => $this->input->post('muc_tieu'),
			'thanh_tich' => $this->input->post('thanh_tich'),
			'thoigian_tn' => $this->input->post('time_tn'),
			'cv' => $this->session->flashdata('message'),
			'active' =>0
			);
		$this->db->where('id', $id_hs);
		$query = $this->db->update('ho_so', $data);
		if($query) {
			return true;
		}else {
			return false;
		}
	}
}